import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';
import 'package:smart_translator/app/widgets/CommonWidgets.dart';
import '../../../style/app_colors.dart';
import '../../../style/widget_style.dart';
import '../controllers/home_controller.dart';

class HomeView extends GetView<HomeController> {
   const HomeView({super.key});

  @override
  Widget build(BuildContext context)  {
    return Scaffold(
        key: controller.scaffoldKey,
        drawerEdgeDragWidth: 0,
        drawer: Drawer(
          backgroundColor: AppColors.scaffold_background_color,
          shape: ContinuousRectangleBorder(),
          child: SingleChildScrollView(
            child: Obx(()=>Container(
              padding: EdgeInsets.all(16.w),
              child: Column(
                children: [
                  SizedBox(height: 52.h,),
                  Container(
                    height: 40.h,
                    padding: EdgeInsets.only(left: 12.w),
                    decoration: BoxDecoration(
                      color: AppColors.swith_inactive_bg_color,
                      borderRadius: BorderRadius.circular(8), // Optional: add border radius
                    ),
                    child: TextField(
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        focusedBorder: InputBorder.none,
                        contentPadding:EdgeInsets.only(left: 10.w),
                        prefixIcon: SizedBox(
                          child: Container(
                            child: Image.asset('assets/images/icon_searchOrReplace_searching.png'),
                          ),
                          width: 16.w,
                          height: 16.h,
                        ),
                        prefixIconConstraints: BoxConstraints(
                          minWidth: 16.w, // 最小宽度
                          minHeight: 16.h, // 最小高度
                        ),
                        hintText: '输入搜索内容',
                        hintStyle: TextStyle(
                            fontSize: 14.sp
                        ),

                      ),
                      onChanged: (v) {
                           controller.searchCustomerFolder(v);
                      },

                    ),
                  ),
                  SizedBox(height: 16.h,),
                  InkWell(
                    child: Container(
                      padding: EdgeInsets.only(top: 14.h,bottom: 14.h,left: 13.h),
                      decoration: BoxDecoration(
                        color: controller.hasAllChecked.value ? Colors.white :  Colors.white.withValues(alpha: 0),
                        borderRadius: BorderRadius.circular(8), // Optional: add border radius
                      ),
                      child: Row(
                        children: [
                          Image.asset('assets/images/icon_slideside_folder.png',width: 16.w,height: 16.h,),
                          SizedBox(width: 5.w,),
                          Text('全部文件(${controller.allSessionCount.value})')
                        ],
                      ),
                    ),
                    onTap: () {
                       controller.allFolderChecked();
                    },
                  ),
                  SizedBox(height: 5.h,),
                  InkWell(
                    onTap: () {
                      controller.unClassifyFolderCheckced();
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        color: controller.hasUnclassify.value ? Colors.white : Colors.white.withValues(alpha: 0),
                        borderRadius: BorderRadius.circular(8), // Optional: add border radius
                      ),
                      padding: EdgeInsets.only(top: 14.h,bottom: 14.h,left: 13.h),
                      child: Row(
                        children: [
                          Image.asset('assets/images/icon_slideside_common.png',width: 16.w,height: 16.h,),
                          SizedBox(width: 5.w,),
                          Text('未分类(${controller.unclassifiedSessionCount.value})')
                        ],
                      ),
                    ),
                  ),
                  SizedBox(height: 5.h,),
                  InkWell(
                    onTap: () {
                      controller.rabishFolderChecked();
                    },
                    child: Container(
                      padding: EdgeInsets.only(top: 14.h,bottom: 14.h,left: 13.h),
                      child: Row(
                        children: [
                          Image.asset('assets/images/icon_slideside_trash.png',width: 16.w,height: 16.h,),
                          SizedBox(width: 5.w,),
                          Text('回收站(${controller.rubbishSessionCount.value})')
                        ],
                      ),
                      decoration: BoxDecoration(
                        color: controller.hasRubbishRecycle.value ? Colors.white : Colors.white.withValues(alpha: 0),
                        borderRadius: BorderRadius.circular(8), // Optional: add border radius
                      ),
                    ),
                  ),
                  SizedBox(height: 17.h,),
                  CommonWidgets.getMyDivider(),
                  SizedBox(height: 17.h,),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('文件夹',style: AppStyleThemeData.HINT_TEXT_STYLE_medium,),
                      InkWell(
                        onTap: () {
                          controller.addNewFolder();
                        },
                        child: Container(
                          padding: EdgeInsets.only(left: 15.w,right: 15.w,top: 10.h,bottom: 10.h),
                          child: Image.asset('assets/images/icon_slideside_adding.png',width: 16.w,height: 16.h,),
                        ),
                      )
                    ],
                  ),
                  Container(
                    child:  Column(
                      children: controller.folderList.value,
                    ),
                  ),
                  SizedBox(height: 30.h,),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('排序方式',style: AppStyleThemeData.HINT_TEXT_STYLE_medium,)
                    ],
                  ),
                  SizedBox(height: 16.h,),
                  InkWell(
                    onTap: () {
                       controller.orderByCreateTime();
                    },
                    child: Container(
                      padding: EdgeInsets.only(top: 14.h,bottom: 14.h,left: 13.h),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('创建时间'),
                          controller.createTimeOrderHasChecked.value ? controller.createTimeOrderType.value ?  SvgPicture.asset('assets/images/icon_orderation_positive.svg',width: 16.w,height: 16.h):
                          Image.asset('assets/images/icon_slideside_orderation.png',width: 16.w,height: 16.h): SizedBox(),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      controller.orderByUpdateTime();
                    },
                    child: Container(
                      padding: EdgeInsets.only(top: 14.h,bottom: 14.h,left: 13.h),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('修改时间'),
                          controller.updateTimeOrderHasChecked.value ? controller.updateTimeOrderType.value ?  SvgPicture.asset('assets/images/icon_orderation_positive.svg',width: 16.w,height: 16.h):
                          Image.asset('assets/images/icon_slideside_orderation.png',width: 16.w,height: 16.h): SizedBox(),
                        ],
                      ),
                    ),
                  )

                ],
              ),
            )
            ),
          ),
        ),
        body: Obx(()=> IndexedStack( /// 在这里修改
          index: controller.currentTabIndex.value,
          children: controller.pages,
        )),
        bottomNavigationBar: Obx(()=>
          Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50.w),
                    color: AppColors.app_base_bgcolor_color,
                    boxShadow: [
                      CommonWidgets.getBoxShadow(),
                    ]
                ),
                child: ClipRRect(
                  borderRadius: BorderRadius.only(topRight: Radius.circular(20.w),topLeft: Radius.circular(20.w)),
                  child: BottomNavigationBar(
                    elevation: 100.w,
                    type: BottomNavigationBarType.fixed,
                    backgroundColor: Colors.white,
                    selectedItemColor: AppColors.app_base_theme_color,
                    unselectedItemColor: AppColors.second_title_color,
                    items: [
                      BottomNavigationBarItem(
                          icon: SvgPicture.asset('assets/images/icon_index_tab_hom_unselected.svg',width: 28.w,height: 28.h),
                          activeIcon: Image.asset('assets/images/icon_index_tab_hom.png',width: 28.w,height: 28.h),
                          label: '首页',
                          backgroundColor: Colors.white
                      ),
                      BottomNavigationBarItem(
                          icon: Image.asset('assets/images/icon_index_tab_video.png',width: 28.w,height: 28.h),
                          activeIcon: SvgPicture.asset('assets/images/icon_index_tab_video_selected.svg',width: 28.w,height: 28.h,color: AppColors.app_base_theme_color,),
                          label: '视频通话',
                          backgroundColor: Colors.white
                      ),
                      BottomNavigationBarItem(
                          icon: Image.asset('assets/images/icon_index_tab_transcript.png',width: 28.w,height: 28.h),
                          activeIcon: SvgPicture.asset('assets/images/icon_index_tab_transcript_selected.svg',width: 28.w,height: 28.h),
                          label: '录音转写',
                          backgroundColor: Colors.white
                      ),
                     /* BottomNavigationBarItem(
                          icon: Image.asset('assets/images/icon_index_tab_doc_trans.png',width: 28.w,height: 28.h),
                          activeIcon: SvgPicture.asset('assets/images/icon_index_tab_doc_trans_selected.svg',width: 28.w,height: 28.h),
                          label: '文档翻译',
                          backgroundColor: Colors.white
                      ),*/
                      BottomNavigationBarItem(
                          icon: Image.asset('assets/images/icon_index_tab_mine.png',width: 28.w,height: 28.h),
                          activeIcon: SvgPicture.asset('assets/images/icon_index_tab_mine_selected.svg',width: 28.w,height: 28.h),
                          label: '我的',
                          backgroundColor: Colors.white
                      ),
                    ],
                    onTap: (index) {
                      controller.onTap(index);
                    },
                    currentIndex: controller.currentTabIndex.value,
                  ),
                )
            )
        )
    );
  }
}
